package day04.homework;

import java.util.Random;
import java.util.Scanner;

public class Guessing {
    public static void main(String[] args) {
        int num, guess;
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int max = 100, min = 1, count = 10;
            num = new Random().nextInt(100) + 1;
            while (count > 0) {
                System.out.println("请输入范围为" + min + "-" + max + "的数字：（输入0退出）");
                guess = scanner.nextInt();
                if (guess == 0) {
                    return;
                } else if (guess < min || guess > max) {
                    System.out.println("输入范围不正确，请重新输入！");
                }else if(num > guess){
                    min = guess;
                    count--;
                    System.out.print("猜小了！还有"+count+"次机会。");
                }else if(guess > num){
                    max = guess;
                    count--;
                    System.out.print("猜大了！还有"+count+"次机会。");
                }else {
                    System.out.println("恭喜你猜对了！一共猜了"+(10-count)+"次。");
                    break;
                }
            }
            if(count==0){
                System.out.println("您的次数已用完，中奖数字为："+num);
            }
        }
    }
}
